<?php

namespace Admin\Assist\Controllers;

/**
 * Created by PhpStorm.
 * User: Lvyj
 * Date: 2017/6/20 0020
 * Time: 14:02
 */
use Helpers\Assets;
use Helpers\Main;
use Helpers\Template;
use Admin\Assist\Service\AssistService as Assist;

class AssistController extends ControllerBase
{
    public function notFoundAction()
    {
        return $this->response->setStatusCode(404)->setJsonContent(['code' => 404, 'error' => 'page not found!']);
    }

    /**
     * 协助列表
     */
    public function indexAction()
    {
        $this->view->pick("assist/list");
        Assets::easyUI('js/assistance.js');
        Template::exists('assistance', 'list') or die(Main::showMessageModal('配置文件不存在，请先创建！', 109106002));
        $listSearchArr = array();
        $listSearchArr[] = array('type' => 'text', 'id' => 'List_Search', 'label' => ' 搜索： ');

        $this->view->setVars(array(
            'List' => Template::createList('List', 'assistance', [
                'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
            ])
        ));
    }

    /**
     * 协助详情:任务列表
     */
    public function detailAction()
    {
        $this->view->pick('assist/index');
        Assets::easyUI('js/task.js');
        Assets::importJs('js/taskOps.js');
        Assets::importJs('js/FileReader.js');
        Assets::importJs('js/upload.js');
        Template::exists('task', 'list') or die(Main::showMessageModal('配置文件不存在，请先创建！', 109106002));
        $formButtonArr = $listButtonArr = $listSearchArr = array();
        $listSearchArr[] = array('type' => 'text', 'id' => 'List_Search', 'label' => ' 搜索： ');
        $listButtonArr[] = array('plain' => 'true', 'id' => 'bt_Task_Add', 'text' => '增加', 'icon' => 'fa-plus');
        $formButtonArr[] = array('id' => 'bt_form_add', 'text' => '下发', 'class' => 'disabled');
        $formButtonArr[] = array('id' => 'bt_form_reset', 'text' => '重置');
        $id = $this->request->get('id');
        $assistance = Assist::getAssistanceInfo($id);
        $result = Assist::getTaskDetail(null, null);

        $this->view->setVars(array(
            'List' => Template::createList('List', 'task', [
                //'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
                'buttonToolbar' => Template::createButtonToolBar($listButtonArr),
            ]),
            'Form' => Template::createForm('task'),
            'FormButton' => Template::createButtonToolBar($formButtonArr),
            'assistance' => $assistance,
            'result' => $result
        ));
    }

    /**
     * 客户端协助请求列表
     */
    public function executingAction()
    {
        $this->view->pick("assist/executing");
        Assets::easyUI('js/request.js');
        Template::exists('request', 'list') or die(Main::showMessageModal('配置文件不存在，请先创建！', 109106002));
        $listSearchArr = array();
        $listSearchArr[] = array('type' => 'text', 'id' => 'List_Search', 'label' => ' 搜索： ');

        $this->view->setVars(array(
            'List' => Template::createList('List', 'request', [
                'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
            ])
        ));
    }

    /**
     * 目录列表
     */
    public function catalogAction()
    {
        $this->view->pick("assist/catalog");
        Assets::easyUI('js/catalog.js');
        Assets::importJs('js/taskOps.js');
        Assets::importJs('js/FileReader.js');
        Assets::importJs('js/upload.js');
        Template::exists('catalog', 'list') or die(Main::showMessageModal('配置文件不存在，请先创建！', 109106002));
        $listSearchArr[] = array();

        $assistId = $this->request->get('assistId');
        $assistance = Assist::getAssistanceInfo($assistId);
        $taskId = $this->request->get('taskId');
        $catalog = Assist::getAssistCatalogInfo($assistId, $taskId);
        $this->view->setVars(array(
            'List' => Template::createList('List', 'catalog', [
                //'searchToolbar' => Template::createSearchToolBar($listSearchArr, true)
            ]),
            'assistance' => $assistance,
            'catalog' => $catalog
        ));
    }

    /**
     * 应用列表
     */
    public function appsAction()
    {
        $this->view->pick("assist/apps");
        Assets::easyUI('js/apps.js');
        Assets::importJs('js/taskOps.js');
        Assets::importJs('js/FileReader.js');
        Assets::importJs('js/upload.js');
        Template::exists('apps', 'list') or die(Main::showMessageModal('配置文件不存在，请先创建！', 109106002));
        $listSearchArr[] = array();

        $assistId = $this->request->get('assistId');
        $assistance = Assist::getAssistanceInfo($assistId);
        $this->view->setVars(array(
            'List' => Template::createList('List', 'apps', [
                //'searchToolbar' => Template::createSearchToolBar($listSearchArr, true)
            ]),
            'assistance' => $assistance
        ));
    }

}